const os = require('os');
const osUtils = require('os-utils');

const getCPUUsage = async () => {
    return new Promise((resolve, reject) => {
        osUtils.cpuUsage(function (currCPU: number) {
            const freeMem = os.freemem() / 1024 / 1024 / 1024;
            const totalMem = os.totalmem() / 1024 / 1024 / 1024;
            const data = {
                cpuUsage: (currCPU * 100.0).toFixed(2) + '%',
                freeMem: freeMem.toFixed(2) + 'G',
                totalMem: totalMem.toFixed(2) + 'G',
                usedMem: (totalMem - freeMem).toFixed(2) + 'G',
                MemUsage: ((totalMem - freeMem) / totalMem * 100.0).toFixed(2) + '%'
            };
            resolve(data);
        });
    });

};

export default getCPUUsage;